package net.chowda.appinject.action;

import net.chowda.appinject.model.AppConfig;
import net.chowda.appinject.model.AppConfigManager;
import net.sourceforge.stripes.action.*;

import java.util.List;

public class BounceAction implements ActionBean {
    String url;
    String action;
    String selectedText;
    List linkTitles;
    List linkUrls;

    @DefaultHandler()
    public Resolution bounce() {
        Resolution res = null;
        try {
            AppConfig appConfig = AppConfigManager.getAppConfig(action);
            if(appConfig.isRedirect()) {
                RedirectResolution redirectResolution = new RedirectResolution(appConfig.getUrl(), false);
                redirectResolution.includeRequestParameters(true);
                res = redirectResolution;
            } else {
                res = new ForwardResolution(appConfig.getUrl());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return res;
    }

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getSelectedText() {
        return selectedText;
    }

    public void setSelectedText(String selectedText) {
        this.selectedText = selectedText;
    }

    public List getLinkTitles() {
        return linkTitles;
    }

    public void setLinkTitles(List linkTitles) {
        this.linkTitles = linkTitles;
    }

    public List getLinkUrls() {
        return linkUrls;
    }

    public void setLinkUrls(List linkUrls) {
        this.linkUrls = linkUrls;
    }

    ActionBeanContext context = null;
    public void setContext(ActionBeanContext actionBeanContext) { context = actionBeanContext; }
    public ActionBeanContext getContext() { return context; }
}
